<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>channeldebug.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_net_channeldebug.js.html">channeldebug.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Definition of the ChannelDebug class. ChannelDebug provides
<a name="line17"></a> * a utility for tracing and debugging the BrowserChannel requests.
<a name="line18"></a> *
<a name="line19"></a> * TODO(user) - allow client to specify a custom redaction policy
<a name="line20"></a> */
<a name="line21"></a>
<a name="line22"></a>
<a name="line23"></a>/**
<a name="line24"></a> * Namespace for BrowserChannel
<a name="line25"></a> */
<a name="line26"></a>goog.provide(&#39;goog.net.ChannelDebug&#39;);
<a name="line27"></a>goog.require(&#39;goog.debug.Logger&#39;);
<a name="line28"></a>goog.require(&#39;goog.json&#39;);
<a name="line29"></a>
<a name="line30"></a>
<a name="line31"></a>
<a name="line32"></a>/**
<a name="line33"></a> * Logs and keeps a buffer of debugging info for the Channel.
<a name="line34"></a> *
<a name="line35"></a> * @constructor
<a name="line36"></a> */
<a name="line37"></a>goog.net.ChannelDebug = function() {
<a name="line38"></a>  /**
<a name="line39"></a>   * The logger instance.
<a name="line40"></a>   * @type {goog.debug.Logger}
<a name="line41"></a>   * @private
<a name="line42"></a>   */
<a name="line43"></a>  this.logger_ = goog.debug.Logger.getLogger(&#39;goog.net.BrowserChannel&#39;);
<a name="line44"></a>};
<a name="line45"></a>
<a name="line46"></a>
<a name="line47"></a>/**
<a name="line48"></a> * Gets the logger used by this ChannelDebug.
<a name="line49"></a> * @return {goog.debug.Logger} The logger used by this ChannelDebug.
<a name="line50"></a> */
<a name="line51"></a>goog.net.ChannelDebug.prototype.getLogger = function() {
<a name="line52"></a>  return this.logger_;
<a name="line53"></a>};
<a name="line54"></a>
<a name="line55"></a>
<a name="line56"></a>/**
<a name="line57"></a> * Logs that the browser went offline during the lifetime of a request.
<a name="line58"></a> * @param {goog.Uri} url The URL being requested.
<a name="line59"></a> */
<a name="line60"></a>goog.net.ChannelDebug.prototype.browserOfflineResponse = function(url) {
<a name="line61"></a>  this.info(&#39;BROWSER_OFFLINE: &#39; + url);
<a name="line62"></a>};
<a name="line63"></a>
<a name="line64"></a>
<a name="line65"></a>/**
<a name="line66"></a> * Logs an XmlHttp request..
<a name="line67"></a> * @param {string} verb The request type (GET/POST).
<a name="line68"></a> * @param {goog.Uri} uri The request destination.
<a name="line69"></a> * @param {string|number|undefined} id The request id.
<a name="line70"></a> * @param {number} attempt Which attempt # the request was.
<a name="line71"></a> * @param {?string} postData The data posted in the request.
<a name="line72"></a> */
<a name="line73"></a>goog.net.ChannelDebug.prototype.xmlHttpChannelRequest =
<a name="line74"></a>    function(verb, uri, id, attempt, postData) {
<a name="line75"></a>  this.info(
<a name="line76"></a>      &#39;XMLHTTP REQ (&#39; + id + &#39;) [attempt &#39; + attempt + &#39;]: &#39; +
<a name="line77"></a>      verb + &#39;\n&#39; + uri + &#39;\n&#39; +
<a name="line78"></a>      this.maybeRedactPostData_(postData));
<a name="line79"></a>};
<a name="line80"></a>
<a name="line81"></a>
<a name="line82"></a>/**
<a name="line83"></a> * Logs the meta data received from an XmlHttp request.
<a name="line84"></a> * @param {string} verb The request type (GET/POST).
<a name="line85"></a> * @param {goog.Uri} uri The request destination.
<a name="line86"></a> * @param {string|number|undefined} id The request id.
<a name="line87"></a> * @param {number} attempt Which attempt # the request was.
<a name="line88"></a> * @param {goog.net.XmlHttp.ReadyState} readyState The ready state.
<a name="line89"></a> * @param {number} statusCode The HTTP status code.
<a name="line90"></a> */
<a name="line91"></a>goog.net.ChannelDebug.prototype.xmlHttpChannelResponseMetaData =
<a name="line92"></a>    function(verb, uri, id, attempt, readyState, statusCode)  {
<a name="line93"></a>  this.info(
<a name="line94"></a>      &#39;XMLHTTP RESP (&#39; + id + &#39;) [ attempt &#39; + attempt + &#39;]: &#39; +
<a name="line95"></a>      verb + &#39;\n&#39; + uri + &#39;\n&#39; + readyState + &#39; &#39; + statusCode);
<a name="line96"></a>};
<a name="line97"></a>
<a name="line98"></a>
<a name="line99"></a>/**
<a name="line100"></a> * Logs the response data received from an XmlHttp request.
<a name="line101"></a> * @param {string|number|undefined} id The request id.
<a name="line102"></a> * @param {?string} responseText The response text.
<a name="line103"></a> * @param {?string=} opt_desc Optional request description.
<a name="line104"></a> */
<a name="line105"></a>goog.net.ChannelDebug.prototype.xmlHttpChannelResponseText =
<a name="line106"></a>    function(id, responseText, opt_desc) {
<a name="line107"></a>  this.info(
<a name="line108"></a>      &#39;XMLHTTP TEXT (&#39; + id + &#39;): &#39; +
<a name="line109"></a>      this.redactResponse_(responseText) +
<a name="line110"></a>      (opt_desc ? &#39; &#39; + opt_desc : &#39;&#39;));
<a name="line111"></a>};
<a name="line112"></a>
<a name="line113"></a>
<a name="line114"></a>/**
<a name="line115"></a> * Logs a Trident ActiveX request.
<a name="line116"></a> * @param {string} verb The request type (GET/POST).
<a name="line117"></a> * @param {goog.Uri} uri The request destination.
<a name="line118"></a> * @param {string|number|undefined} id The request id.
<a name="line119"></a> * @param {number} attempt Which attempt # the request was.
<a name="line120"></a> */
<a name="line121"></a>goog.net.ChannelDebug.prototype.tridentChannelRequest =
<a name="line122"></a>    function(verb, uri, id, attempt) {
<a name="line123"></a>  this.info(
<a name="line124"></a>      &#39;TRIDENT REQ (&#39; + id + &#39;) [ attempt &#39; + attempt + &#39;]: &#39; +
<a name="line125"></a>      verb + &#39;\n&#39; + uri);
<a name="line126"></a>};
<a name="line127"></a>
<a name="line128"></a>
<a name="line129"></a>/**
<a name="line130"></a> * Logs the response text received from a Trident ActiveX request.
<a name="line131"></a> * @param {string|number|undefined} id The request id.
<a name="line132"></a> * @param {string} responseText The response text.
<a name="line133"></a> */
<a name="line134"></a>goog.net.ChannelDebug.prototype.tridentChannelResponseText =
<a name="line135"></a>    function(id, responseText) {
<a name="line136"></a>  this.info(
<a name="line137"></a>      &#39;TRIDENT TEXT (&#39; + id + &#39;): &#39; +
<a name="line138"></a>      this.redactResponse_(responseText));
<a name="line139"></a>};
<a name="line140"></a>
<a name="line141"></a>
<a name="line142"></a>/**
<a name="line143"></a> * Logs the done response received from a Trident ActiveX request.
<a name="line144"></a> * @param {string|number|undefined} id The request id.
<a name="line145"></a> * @param {boolean} successful Whether the request was successful.
<a name="line146"></a> */
<a name="line147"></a>goog.net.ChannelDebug.prototype.tridentChannelResponseDone =
<a name="line148"></a>    function(id, successful) {
<a name="line149"></a>  this.info(
<a name="line150"></a>      &#39;TRIDENT TEXT (&#39; + id + &#39;): &#39; + successful ? &#39;success&#39; : &#39;failure&#39;);
<a name="line151"></a>};
<a name="line152"></a>
<a name="line153"></a>
<a name="line154"></a>/**
<a name="line155"></a> * Logs a request timeout.
<a name="line156"></a> * @param {goog.Uri} uri The uri that timed out.
<a name="line157"></a> */
<a name="line158"></a>goog.net.ChannelDebug.prototype.timeoutResponse = function(uri) {
<a name="line159"></a>  this.info(&#39;TIMEOUT: &#39; + uri);
<a name="line160"></a>};
<a name="line161"></a>
<a name="line162"></a>
<a name="line163"></a>/**
<a name="line164"></a> * Logs a debug message.
<a name="line165"></a> * @param {string} text The message.
<a name="line166"></a> */
<a name="line167"></a>goog.net.ChannelDebug.prototype.debug = function(text) {
<a name="line168"></a>  this.info(text);
<a name="line169"></a>};
<a name="line170"></a>
<a name="line171"></a>
<a name="line172"></a>/**
<a name="line173"></a> * Logs an exception
<a name="line174"></a> * @param {Error} e The error or error event.
<a name="line175"></a> * @param {string=} opt_msg The optional message, defaults to &#39;Exception&#39;.
<a name="line176"></a> */
<a name="line177"></a>goog.net.ChannelDebug.prototype.dumpException = function(e, opt_msg) {
<a name="line178"></a>  this.severe((opt_msg || &#39;Exception&#39;) + e);
<a name="line179"></a>};
<a name="line180"></a>
<a name="line181"></a>
<a name="line182"></a>/**
<a name="line183"></a> * Logs an info message.
<a name="line184"></a> * @param {string} text The message.
<a name="line185"></a> */
<a name="line186"></a>goog.net.ChannelDebug.prototype.info = function(text) {
<a name="line187"></a>  this.logger_.info(text);
<a name="line188"></a>};
<a name="line189"></a>
<a name="line190"></a>
<a name="line191"></a>/**
<a name="line192"></a> * Logs a warning message.
<a name="line193"></a> * @param {string} text The message.
<a name="line194"></a> */
<a name="line195"></a>goog.net.ChannelDebug.prototype.warning = function(text) {
<a name="line196"></a>  this.logger_.warning(text);
<a name="line197"></a>};
<a name="line198"></a>
<a name="line199"></a>
<a name="line200"></a>/**
<a name="line201"></a> * Logs a severe message.
<a name="line202"></a> * @param {string} text The message.
<a name="line203"></a> */
<a name="line204"></a>goog.net.ChannelDebug.prototype.severe = function(text) {
<a name="line205"></a>  this.logger_.severe(text);
<a name="line206"></a>};
<a name="line207"></a>
<a name="line208"></a>
<a name="line209"></a>/**
<a name="line210"></a> * Removes potentially private data from a response so that we don&#39;t
<a name="line211"></a> * accidentally save private and personal data to the server logs.
<a name="line212"></a> * @param {?string} responseText A JSON response to clean.
<a name="line213"></a> * @return {?string} The cleaned response.
<a name="line214"></a> * @private
<a name="line215"></a> */
<a name="line216"></a>goog.net.ChannelDebug.prototype.redactResponse_ = function(responseText) {
<a name="line217"></a>  // first check if it&#39;s not JS - the only non-JS should be the magic cookie
<a name="line218"></a>  if (!responseText ||
<a name="line219"></a>      /** @suppress {missingRequire}.  The require creates a circular
<a name="line220"></a>       *  dependency.
<a name="line221"></a>       */
<a name="line222"></a>      responseText == goog.net.BrowserChannel.MAGIC_RESPONSE_COOKIE) {
<a name="line223"></a>    return responseText;
<a name="line224"></a>  }
<a name="line225"></a>  /** @preserveTry */
<a name="line226"></a>  try {
<a name="line227"></a>    var responseArray = goog.json.unsafeParse(responseText);
<a name="line228"></a>    if (responseArray) {
<a name="line229"></a>      for (var i = 0; i &lt; responseArray.length; i++) {
<a name="line230"></a>        if (goog.isArray(responseArray[i])) {
<a name="line231"></a>          this.maybeRedactArray_(responseArray[i]);
<a name="line232"></a>        }
<a name="line233"></a>      }
<a name="line234"></a>    }
<a name="line235"></a>
<a name="line236"></a>    return goog.json.serialize(responseArray);
<a name="line237"></a>  } catch (e) {
<a name="line238"></a>    this.debug(&#39;Exception parsing expected JS array - probably was not JS&#39;);
<a name="line239"></a>    return responseText;
<a name="line240"></a>  }
<a name="line241"></a>};
<a name="line242"></a>
<a name="line243"></a>
<a name="line244"></a>/**
<a name="line245"></a> * Removes data from a response array that may be sensitive.
<a name="line246"></a> * @param {Array} array The array to clean.
<a name="line247"></a> * @private
<a name="line248"></a> */
<a name="line249"></a>goog.net.ChannelDebug.prototype.maybeRedactArray_ = function(array) {
<a name="line250"></a>  if (array.length &lt; 2) {
<a name="line251"></a>    return;
<a name="line252"></a>  }
<a name="line253"></a>  var dataPart = array[1];
<a name="line254"></a>  if (!goog.isArray(dataPart)) {
<a name="line255"></a>    return;
<a name="line256"></a>  }
<a name="line257"></a>  if (dataPart.length &lt; 1) {
<a name="line258"></a>    return;
<a name="line259"></a>  }
<a name="line260"></a>
<a name="line261"></a>  var type = dataPart[0];
<a name="line262"></a>  if (type != &#39;noop&#39; &amp;&amp; type != &#39;stop&#39;) {
<a name="line263"></a>    // redact all fields in the array
<a name="line264"></a>    for (var i = 1; i &lt; dataPart.length; i++) {
<a name="line265"></a>      dataPart[i] = &#39;&#39;;
<a name="line266"></a>    }
<a name="line267"></a>  }
<a name="line268"></a>};
<a name="line269"></a>
<a name="line270"></a>
<a name="line271"></a>/**
<a name="line272"></a> * Removes potentially private data from a request POST body so that we don&#39;t
<a name="line273"></a> * accidentally save private and personal data to the server logs.
<a name="line274"></a> * @param {?string} data The data string to clean.
<a name="line275"></a> * @return {?string} The data string with sensitive data replaced by &#39;redacted&#39;.
<a name="line276"></a> * @private
<a name="line277"></a> */
<a name="line278"></a>goog.net.ChannelDebug.prototype.maybeRedactPostData_ = function(data) {
<a name="line279"></a>  if (!data) {
<a name="line280"></a>    return null;
<a name="line281"></a>  }
<a name="line282"></a>  var out = &#39;&#39;;
<a name="line283"></a>  var params = data.split(&#39;&amp;&#39;);
<a name="line284"></a>  for (var i = 0; i &lt; params.length; i++) {
<a name="line285"></a>    var param = params[i];
<a name="line286"></a>    var keyValue = param.split(&#39;=&#39;);
<a name="line287"></a>    if (keyValue.length &gt; 1) {
<a name="line288"></a>      var key = keyValue[0];
<a name="line289"></a>      var value = keyValue[1];
<a name="line290"></a>
<a name="line291"></a>      var keyParts = key.split(&#39;_&#39;);
<a name="line292"></a>      if (keyParts.length &gt;= 2 &amp;&amp; keyParts[1] == &#39;type&#39;) {
<a name="line293"></a>        out += key + &#39;=&#39; + value + &#39;&amp;&#39;;
<a name="line294"></a>      } else {
<a name="line295"></a>        out += key + &#39;=&#39; + &#39;redacted&#39; + &#39;&amp;&#39;;
<a name="line296"></a>      }
<a name="line297"></a>    }
<a name="line298"></a>  }
<a name="line299"></a>  return out;
<a name="line300"></a>};
</pre>


</body>
</html>
